package com.risenb.view;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.web.servlet.view.document.AbstractExcelView;
import com.risenb.bean.QQContract;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.OutputStream;
import java.util.List;
import java.util.Map;

/**
 * 
 * @author zhaocj
 *
 *         2017年9月29日
 */
public class QQNumberExcelView extends AbstractExcelView {
	@Override
	@SuppressWarnings("unchecked")
	protected void buildExcelDocument(Map<String, Object> map, HSSFWorkbook hssfWorkbook,
			HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
		HSSFSheet sheet = hssfWorkbook.createSheet("导入模板");
		Row header = sheet.createRow(0);
		header.createCell(0).setCellValue("姓");
		header.createCell(1).setCellValue("名");
		header.createCell(2).setCellValue("昵称");
		header.createCell(3).setCellValue("QQ号");
		header.createCell(4).setCellValue("家庭手机");
		header.createCell(5).setCellValue("工作手机");
		header.createCell(6).setCellValue("其他手机");
		header.createCell(7).setCellValue("家庭电话");
		header.createCell(8).setCellValue("工作电话");
		header.createCell(9).setCellValue("其他电话");
		header.createCell(10).setCellValue("家庭传真");
		header.createCell(11).setCellValue("工作传真");
		header.createCell(12).setCellValue("公司/部门");
		header.createCell(13).setCellValue("家庭地址");
		header.createCell(14).setCellValue("工作地址");
		header.createCell(15).setCellValue("其他地址");
		header.createCell(16).setCellValue("备注");
		header.createCell(17).setCellValue("电子邮件");
		header.createCell(18).setCellValue("家庭邮箱");
		header.createCell(19).setCellValue("办公邮箱");
		header.createCell(20).setCellValue("网址");
		header.createCell(21).setCellValue("家庭网址");
		header.createCell(22).setCellValue("办公网址");
		header.createCell(23).setCellValue("生日");
		header.createCell(24).setCellValue("职务");
		List<QQContract> list = (List<QQContract>) map.get("data");
		for (int i = 0; i < list.size(); i++) {
			QQContract data = list.get(i);
			Row row = sheet.createRow(i + 1);
			row.createCell(0).setCellValue(data.getFirstName());
			row.createCell(1).setCellValue(data.getLastName());
			row.createCell(2).setCellValue(data.getNickName());
			row.createCell(3).setCellValue(data.getQqNumber());
			row.createCell(4).setCellValue(data.getHomePhone());
			row.createCell(5).setCellValue(data.getWorkPhone());
			row.createCell(6).setCellValue(data.getOtherPhone());
			row.createCell(7).setCellValue(data.getHomeMobile());
			row.createCell(8).setCellValue(data.getWorkMobile());
			row.createCell(10).setCellValue(data.getOtherMobile());
			row.createCell(11).setCellValue(data.getHomeFax());
			row.createCell(12).setCellValue(data.getWorkFax());
			row.createCell(13).setCellValue(data.getHomeAddress());
			row.createCell(14).setCellValue(data.getWorkAddress());
			row.createCell(15).setCellValue(data.getOtherAddress());
			row.createCell(16).setCellValue(data.getRemark());
			row.createCell(17).setCellValue(data.getPersonalEmail());
			row.createCell(18).setCellValue(data.getHomeemail());
			row.createCell(19).setCellValue(data.getWorkEmail());
			row.createCell(20).setCellValue(data.getPersonalUrl());
			row.createCell(21).setCellValue(data.getHomeUrl());
			row.createCell(22).setCellValue(data.getWorkUrl());
			row.createCell(23).setCellValue(data.getBirthday());
			row.createCell(24).setCellValue(data.getDuty());
		}
		httpServletResponse.setContentType("application/vnd.ms-excel");
		httpServletResponse.setHeader("Content-disposition", "attachment;filename=qqExcel.xls");
		OutputStream ouputStream = httpServletResponse.getOutputStream();
		hssfWorkbook.write(ouputStream);
		ouputStream.flush();
		ouputStream.close();
	}
}
